package redis

import "strconv"

const GoodsStockKey = "GoodsStock:goodsId_"

// 同步虚拟库存
func SyncGoodsStock(goodsId, stock int) {

	key := GoodsStockKey + strconv.Itoa(goodsId)

	for i := 0; i < stock; i++ {
		RedisDB.RPush(key, goodsId)
	}
}

// 获取虚拟库存
func GetGoodsStock(goodsId int) int64 {

	key := GoodsStockKey + strconv.Itoa(goodsId)
	return RedisDB.LLen(key).Val()
}

// 删除虚拟库存
func DelGoodsStock(goodsId, stock int) {

	key := GoodsStockKey + strconv.Itoa(goodsId)

	for i := 0; i < stock; i++ {
		RedisDB.LPop(key)
	}
}
